package pl.planito.manager;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import pl.planito.entity.User;
import pl.planito.user.info.UserDataBridge;
import pl.planito.user.managament.IUserRegisterLocal;
import pl.planito.util.PasswordUtility;

/**
 * Session Bean implementation class UserRegister
 */
@Stateless
public class UserRegisterImpl implements IUserRegisterLocal {
	@PersistenceContext
	private EntityManager entityManager;
    /**
     * Default constructor. 
     */
    public UserRegisterImpl() {
    }

	public String registerUser(UserDataBridge userData) {
		User user = new User();
		byte b = (byte)(userData.getBlocked()?0:1);
		PasswordUtility pass = new PasswordUtility();
		
		user.setSalt(pass.getSalt());
		user.setBlocked(b);
		user.setEmail(userData.getEmail());
		user.setLogin(userData.getLogin());
		user.setName(userData.getName());
		user.setPassword(pass.getMD5(new StringBuilder(userData.getPassword())));
		entityManager.persist(user);
		
		return null;
	}
	
	public String activateUser(String token) {
		return null;
	}

	public void modifyUser(String id) {
		// TODO Auto-generated method stub	
	}

}
